import request from '@/utils/request'

export function saveRole(params) {
  return request({
    url: '/admin/role/create',
    method: 'post',
    data: params
  })
}

export function updateRole(params) {
  return request({
    url: '/admin/role/update',
    method: 'post',
    data: params
  })
}

export function validRole(id) {
  return request({
    url: '/admin/role/valid/' + id,
    method: 'post'
  })
}

export function invalidRole(id) {
  return request({
    url: '/admin/role/invalid/' + id,
    method: 'post'
  })
}

export function findRolesByPage(params) {
  return request({
    url: '/admin/role/findByPage',
    method: 'post',
    data: params
  })
}

export function findValidRoles(params) {
  return request({
    url: '/admin/role/findAllValidRoles',
    method: 'post',
    data: params
  })
}

export function getUsersByRoleCode(params) {
  return request({
    url: '/admin/role/getAllUsersByRoleCode',
    method: 'post',
    data: params
  })
}

export function getUserByRoleId(params) {
  return request({
    url: '/admin/role/getAllUsersByRoleId',
    method: 'post',
    data: params
  })
}

export function getUserByRoleName(params) {
  return request({
    url: '/admin/role/getAllUsersByRoleName',
    method: 'post',
    data: params
  })
}

export function grantRoleResources(params) {
  return request({
    url: '/admin/role/grantRoleResources',
    method: 'post',
    data: params
  })
}

export function getResourceTreeByRoleId(roleId) {
  return request({
    url: '/admin/role/getResourceTreeById',
    method: 'post',
    params: { roleId: roleId }
  })
}

export function getRoleResourceIds(roleId) {
  return request({
    url: '/admin/role/getRoleResourceIds/' + roleId,
    method: 'post'
  })
}

export function getAllValidRoles() {
  return request({
    url: '/admin/role/findAllValidRoles',
    method: 'post'
  })
}
